package com.zy.openchat.util;

import android.os.Bundle;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.ja.openchat.R;
import com.ja.openchat.ui.found.CircleTopicActivity;
import com.ja.openchat.ui.me.MyAlbumFragment;
import com.zy.openchat.App;
import com.zy.openchat.core.model.circle.CircleTopicInfo;

import me.goldze.mvvmhabit.base.BaseActivity;

public class CircleMentionSpan extends ClickableSpan {
    private long uid;
    private CircleTopicInfo topicInfo;

    public CircleMentionSpan(long uid, CircleTopicInfo topicInfo) {
        this.uid = uid;
        this.topicInfo = topicInfo;
    }

    public String getTopic(){
        return topicInfo==null?"":topicInfo.name;
    }

    public long getUid() {
        return uid;
    }

    public boolean isUserType() {
        return topicInfo==null;
    }

    @Override
    public void updateDrawState(@NonNull TextPaint ds) {
        ds.setColor(ContextCompat.getColor(App.getInstanse(), R.color.login_btn_bg_color));
    }

    @Override
    public void onClick(@NonNull View widget) {
        if(topicInfo!=null){
//            if(topicInfo.id!=0){
                CircleTopicActivity.start(widget.getContext(),topicInfo.name);
//            }
        }else{
            if(widget.getContext() instanceof BaseActivity&& ((BaseActivity)widget.getContext()).getViewModel()!=null){
                Bundle bundle = new Bundle();
                bundle.putLong("userId", uid);
                ((BaseActivity)widget.getContext()).getViewModel().startContainerActivity(MyAlbumFragment.class.getCanonicalName(), bundle);
            }
        }
    }
}

